package com.yikaiye.android.yikaiye.ui.activity.viewmodel;

import androidx.lifecycle.MutableLiveData;

import com.yikaiye.android.yikaiye.base.BaseViewModel;
import com.yikaiye.android.yikaiye.config.Constant;
import com.yikaiye.android.yikaiye.di.retrofit.BaseModel;
import com.yikaiye.android.yikaiye.di.retrofit.BaseNetCallback;
import com.yikaiye.android.yikaiye.model.OrderDataModel;
import com.yikaiye.android.yikaiye.model.VersionModel;

public class MainViewModel extends BaseViewModel {

    public MutableLiveData<VersionModel> versionModelMutableLiveData = new MutableLiveData<>();
    public MutableLiveData<OrderDataModel> orderDataModelMutableLiveData = new MutableLiveData<>();

    /**
     * 版本更新
     */
    public void checkVersion() {
        addSubscribe(mRetrofitHelper.checkVersion().subscribeWith(new BaseNetCallback<VersionModel>() {

            @Override
            public void onSuccess(BaseModel<VersionModel> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode()) {
                    versionModelMutableLiveData.setValue(baseModel.getData());
                }
            }
        }));
    }

    /**
     * 查询预订单
     */
    public void getOrderList() {
        addSubscribe(mRetrofitHelper.getOrderList().subscribeWith(new BaseNetCallback<OrderDataModel>() {

            @Override
            public void onSuccess(BaseModel<OrderDataModel> baseModel) {
                if (Constant.SUCCESS == baseModel.getCode()) {
                    orderDataModelMutableLiveData.setValue(baseModel.getData());
                }
            }
        }));
    }
}
